<template>
    <fs-page class="PageFeatureSearchMulti">
        <fs-crud ref="crudRef" v-bind="crudBinding">
            <template #actionbar-right>
                <importExcel api="api/stock-record/" v-auth="'StockRecord:Import'" @completed="handleImportCompleted">导入</importExcel>
            </template>
        </fs-crud>
    </fs-page>
</template>

<script lang="ts">
import { onMounted, getCurrentInstance, defineComponent, ref, provide } from 'vue';
import { useFs } from '@fast-crud/fast-crud';
import createCrudOptions from './crud';
import importExcel from '/@/components/importExcel/index.vue';
import { ElMessage } from 'element-plus';

export default defineComponent({
    name: "StockRecord",
    components: { importExcel },
    setup() {
        const instance = getCurrentInstance();
        const context: any = {
            componentName: instance?.type.name
        };

        const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions, context });
        
        // 添加刷新视图方法，供importExcel组件使用
        const refreshView = () => {
            crudExpose.doRefresh();
            ElMessage.success('数据已刷新');
        };
        
        // 导入完成后的回调
        const handleImportCompleted = () => {
            refreshView();
        };
        
        // 提供刷新方法给子组件
        provide('refreshView', refreshView);

        onMounted(() => {
            crudExpose.doRefresh();
        });

        return {
            crudBinding,
            crudRef,
            handleImportCompleted
        };
    }
});
</script> 